GtkFontChooserWidget: Allow fractional font sizes
authorMatthias Clasen <mclasen@redhat.com>
Fri, 15 Aug 2014 18:57:31 +0000 (14:57 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 15 Aug 2014 18:57:31 +0000 (14:57 -0400)
With this change, we let users enter up to 2 decimals in the entry,
to specify font sizes exactly. The slider still rounds to whole
numbers.

https://bugzilla.gnome.org/show_bug.cgi?id=665711

gtk/gtkfontchooserwidget.c
gtk/resources/ui/gtkfontchooserwidget.ui

index 1edd2cd896e976f8353044f13c21c4df7bd6ece1..e7d347d7c55f60fed952ccef913c2b72cb1ac2da 100644 (file)
@@ -262,6 +262,23 @@ size_change_cb (GtkAdjustment *adjustment,
   gtk_font_chooser_widget_take_font_desc (fontchooser, font_desc);
 }
 
+static gboolean
+output_cb (GtkSpinButton *spin,
+           gpointer       data)
+{
+  GtkAdjustment *adjustment;
+  gchar *text;
+  gdouble value;
+
+  adjustment = gtk_spin_button_get_adjustment (spin);
+  value = gtk_adjustment_get_value (adjustment);
+  text = g_strdup_printf ("%2.4g", value);
+  gtk_entry_set_text (GTK_ENTRY (spin), text);
+  g_free (text);
+
+  return TRUE;
+}
+
 static void
 gtk_font_chooser_widget_update_marks (GtkFontChooserWidget *fontchooser)
 {
@@ -516,6 +533,7 @@ gtk_font_chooser_widget_class_init (GtkFontChooserWidgetClass *klass)
   gtk_widget_class_bind_template_callback (widget_class, row_inserted_cb);
   gtk_widget_class_bind_template_callback (widget_class, row_deleted_cb);
   gtk_widget_class_bind_template_callback (widget_class, size_change_cb);
+  gtk_widget_class_bind_template_callback (widget_class, output_cb);
 }
 
 static void
index c12bdab604479433d9558be048d704083193bc95..c2c599dc91fe775a8bd0268ca6e994b06c644466 100644 (file)
             <property name="can_focus">True</property>
             <property name="hexpand">True</property>
             <property name="adjustment">slider_adjustment</property>
-            <property name="digits">0</property>
             <property name="draw_value">False</property>
+            <property name="round-digits">0</property>
             <signal name="scroll-event" handler="resize_by_scroll_cb" swapped="no"/>
           </object>
           <packing>
             <property name="can_focus">True</property>
             <property name="invisible_char">•</property>
             <property name="adjustment">spin_adjustment</property>
+            <signal name="output" handler="output_cb"/>
           </object>
           <packing>
             <property name="left_attach">1</property>